public class IsPowerOfTwo {

    public boolean isPowerOfTwo(int n) {
        if (n < 0) return false;
        int count = 0;
        for (int i = 0; i < 32; i++) {
            int k = n & 1;
            if (k == 1) count++;
            if (count > 1) break;
            n = n >> 1;
        }
        return count == 1 ? true : false;
    }
}
